/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sim_test;

import java.awt.Image;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author Administrator
 */
public class Sim_ImageLoader {
    
    private int sizeOfTiles;
    private ArrayList<Image[]> alAllImages = new ArrayList<Image[]>();
    private ArrayList<String> alNameOfObjectsWithImages = new ArrayList<String>();
    
    public Sim_ImageLoader(int tileSize)
    {
        sizeOfTiles = tileSize;
        loadCarImages();
    }
    
    private void loadCarImages()
    {
        String[] filesInCarDirectory;
        Image[] carImages = new Image[4]; // change later
        
        URL directoryURL = getClass().getResource("Scenarios/Scenario1/Map/ObjectImages/");
        File startingDirectory = new File("blank");
        try {
            startingDirectory = new File(directoryURL.toURI());
            }catch(URISyntaxException e) {
            System.err.println("error loading car images, conversion from URL to file failed");
        }
        
        String strFullPathToCarDirectory = startingDirectory.getAbsolutePath() + "\\car1\\";
        File carDirectory = new File(strFullPathToCarDirectory);
        filesInCarDirectory = carDirectory.list();
        
        
        for(int i = 0; i < filesInCarDirectory.length; i++)
        {
            String s = strFullPathToCarDirectory + filesInCarDirectory[i];
            ImageIcon currentImage = new ImageIcon(s);
            Image imgToBeScaled = currentImage.getImage();
            currentImage = new ImageIcon( resizeImageToTileSize(imgToBeScaled) ); // scale image to tilesize
            carImages[i] = currentImage.getImage();
        }
        
        alAllImages.add(carImages);
        alNameOfObjectsWithImages.add(carDirectory.getName());
        
    }
    
    private Image resizeImageToTileSize(Image img)
    {
        img = img.getScaledInstance(sizeOfTiles, sizeOfTiles, Image.SCALE_DEFAULT);
        return img;
    }
    
    public Image[] getCar1Images()
    {
        return alAllImages.get(0);
    }

}
